package com.study.hot.jetpack.paging

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import com.study.hot.R
import com.study.hot.jetpack.room.test_address.db.Address
import com.study.hot.jetpack.room.test_address.repository.AddressRepository
import kotlinx.android.synthetic.main.activity_paging.*

/**
 * <pre>
 *     author : fauks
 *     time   : 2020/03/25
 *     desc   :
 * </pre>
 */
class PagingActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_paging)

        val datas: LiveData<PagedList<Address>> = LivePagedListBuilder(AddressRepository.newInstance(this).addressDao.getAddressForPage(), 15).build()
        val pageAdapter = PagingAdapter()
        pagingRecyclerView.adapter = pageAdapter
        datas.observe(this, Observer {
            pageAdapter.submitList(it)
        })
    }
}